/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.testis.utils;


/**
 *
 * @author root
 */
public class StackTrace
{

    public static String getCurrentlyExecutingMethodName()
    {

        Throwable t = new Throwable();
        StackTraceElement[] elements = t.getStackTrace();
        if (elements.length <= 0) {
            return "[No Stack Information Available]";
        // elements[0] is this method
        }
        if (elements.length < 2) {
            return null;
        }
        return elements[1].getMethodName();
    }


    public static String getCurrentlyExecutingClassName()
    {

        Throwable t = new Throwable();
        StackTraceElement[] elements = t.getStackTrace();
        if (elements.length <= 0) {
            return "[No Stack Information Available]";
        // elements[0] is this method
        }
        if (elements.length < 2) {
            return null;
        }
        return elements[1].getClassName();
    }


    public static String getExecutingClassNameByIndex(int index)
    {

        Throwable t = new Throwable();
        StackTraceElement[] elements = t.getStackTrace();
        if (elements.length <= 0) {
            return "[No Stack Information Available]";
        // elements[0] is this method
        }
        if (elements.length < index + 1) {
            return null;
        }
        return elements[index].getClassName();
    }
}
